package com.kaifamiao.service.imp;

import com.kaifamiao.mapper.DoctorMapper;
import com.kaifamiao.pojo.Doctor;
import com.kaifamiao.service.IDoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorService implements IDoctorService {
    @Autowired
    DoctorMapper mapper = null;

    /**
     * 所有医生(有医生所在部门名称)
     * @return
     */
    @Override
    public List<Doctor> findAll() {
        List<Doctor> doctorList = mapper.findAll();
//        System.out.println(doctorList);
        return doctorList;
    }

    /**
     *通过医生编号查询医生
     * @param id
     * @return
     */
    @Override
    public Doctor findById(int id) {
        Doctor doctor = mapper.findById(id);
        return doctor;
    }

    /**
     * 通过医生登录用户名查询医生信息
     * @param username
     * @return
     */
    @Override
    public Doctor findByUsername(String username) {
        return mapper.findByUsername(username);
    }

    @Override
    public Doctor findByPhoneNumber(String phoneNumber) {
        return mapper.findByPhoneNumber(phoneNumber);
    }

    /**
     * 通过部门编号查询医生
     * @param id
     * @return
     */
    @Override
    public List<Doctor> findByDepartmentId(int id) {
        return mapper.findByDepartmentId(id);
    }

    /**
     * 添加医生
     * @param doctor
     * @return
     */
    @Override
    public boolean addDoctor(Doctor doctor) {
        int row = mapper.addDoctor(doctor);
        if (row>0){
            return true;
        }
        return false;
    }

    /**
     * 修改医生
     * @param doctor
     * @return
     */
    @Override
    public boolean update(Doctor doctor) {
        int row = mapper.update(doctor);
        if (row>0){
            return true;
        }
        return false;
    }

    /**
     * 删除医生
     * @param id
     * @return
     */
    @Override
    public boolean delete(int id) {
        int row = mapper.delete(id);
        if (row>0){
            return true;
        }
        return false;
    }

    /**
     * 最多可预约患者总数
     * @return
     */
    @Override
    public int maxPatientsSum() {
        return mapper.maxPatientsSum();
    }


}
